package com.talkingdata.hadoop.guard.controller;

import com.talkingdata.hadoop.guard.bean.DfsClusterState;
import com.talkingdata.hadoop.guard.bean.NameNodeState;
import com.talkingdata.hadoop.guard.mapper.DfsClusterMapper;
import com.talkingdata.hadoop.guard.mapper.NamenodeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

@Controller
public class ClusterHdfsInfoController {

    @Autowired
    private DfsClusterMapper dfsClusterMapper;

    @Autowired
    private NamenodeMapper namenodeMapper;

    @RequestMapping("/cluster_hdfs_info")
    public ModelAndView clusterHdfsInfo(String clusterId ){
        ModelAndView mav = new ModelAndView("cluster_hdfs_info");
        DfsClusterState dfsClusterState = null;
        ArrayList<NameNodeState> nameNodeStatesList = null;
        try {
            dfsClusterState = dfsClusterMapper.selectDfsClusterStateByServiceId(clusterId);
            nameNodeStatesList = namenodeMapper.selectNameNodeStatebyServiceId(clusterId);
        } catch (Exception e) {
            System.out.println( clusterId + " dfsClusterState or nameNodeState conn db failed ");
            e.printStackTrace();
        }
        mav.addObject("nameNodeStatesList",nameNodeStatesList);
        mav.addObject("dfsClusterState",dfsClusterState);
        return mav;
    }
}
